# 高阶函数：
# 函数可以作为参数传递给其他函数
# 函数可以作为返回值从其他函数返回


def apply_operation(nums, operateFunction):
    """对nums中的每个元素应用operateFunction函数"""
    return [operateFunction(num) for num in nums]


def square(num):
    return num**2


def double(num):
    return num * 2


def caculArea(num):
    import math

    return math.pi * num**2


nums = [1, 2, 3, 4, 5]

squares = apply_operation(nums, square)  # [1, 4, 9, 16, 25]

doubles = apply_operation(nums, double)  # [2, 4, 6, 8, 10]

# [3.141592653589793, 12.566370614359172, 28.274333882308138, 50.26548245743669, 78.53981633974483]
areas = apply_operation(nums, caculArea)


print(squares, doubles, areas)


# 函数作为返回值
def greet(name):
    def inner(age):
        return f"Hello, {name}, you are {age} years old!"

    return inner


new_func = greet("Alice")

print(new_func(10))
